package cn.ilovese.collect.controller.report;

import cn.ilovese.collect.po.report.Report;
import cn.ilovese.collect.po.similarity.TextSimilarity;
import cn.ilovese.collect.service.report.ReportService;
import cn.ilovese.collect.service.report.similaritystrategy.TextSimilarityStrategy;
import cn.ilovese.collect.serviceimpl.report.similaritystrategy.Word2VecStrategy;
import cn.ilovese.collect.vo.ResultVO;
import cn.ilovese.collect.vo.report.*;
import cn.ilovese.collect.vo.user.UserVO;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.soap.Text;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/report")
public class ReportController {

    @Resource
    ReportService reportService;

    //三个注解配置接收前端调用时传给的参数，你们自己根据需要给每个Controller方法的参数添加
    //@RequestBody，接收前端传递给后端的json字符串中的数据的(请求体中的数据的)
    //@RequestParam，将请求参数绑定到你控制器的方法参数上（是springmvc中接收普通参数的注解）
    //@PathVariable，接收请求路径中占位符的值

    // 提交填写完成的报告，目前还不知道是对应前端哪个路由，用的get还是post方法，先都用post替代
    @PostMapping("/submit")
    ResultVO<ReportVO> submitReport(@RequestBody ReportFormVO report){
        System.err.println("submit report!");
        return reportService.createReport(report);
    }

    // 发布者获得目前收到的报告列表，目前还不知道是对应前端哪个路由，用的get还是post方法，先都用post替代
    @GetMapping("/reportlist/{taskId}")
    ResultVO<List<ReportWithWorkerNameVO>> getReportList(@PathVariable Integer taskId){
        return reportService.getReportList(taskId);
    }

    // 发布者查看某一具体报告，目前还不知道是对应前端哪个路由，用的get还是post方法，先都用post替代
    @GetMapping("/bossdetail/{reportId}")
    ResultVO<ReportVO> getReport(@PathVariable Integer reportId){
        //System.out.println("in view report");
        return reportService.getReport(reportId);
    }

    //TODO
    @GetMapping("/workerdetail/{taskid}")
    ResultVO<ReportWithSimilarityVO> getReportByTaskAndUser(@PathVariable Integer taskid, @RequestParam Integer workerid) throws IOException {
        return reportService.getReportByTaskAndUser(workerid,taskid);
    }

    @GetMapping("/workerdetail/report/{reportId}")
    ResultVO<ReportWithSimilarityVO> getReportByReportid(@PathVariable Integer reportId) throws IOException {
        return reportService.getReportByReportId(reportId);
    }

    /**
     * 查询一篇report和同task中已经提交的其他report的相似度
     * @param reportFormVO
     * @return
     */
    @GetMapping("/similarity/duplicate/{taskid}")
    ResultVO<DuplicateVO> getReportDuplication(@RequestBody ReportFormVO reportFormVO,@PathVariable Integer taskid){
        return reportService.getReportDuplication(reportFormVO,taskid);
    }

    /**
     * 查询两篇report彼此之间的相似度，传入两篇报告的id
     * @param
     * @return
     */
    @GetMapping("/similarity/1to1")
    ResultVO<DuplicateVO> getReportSimilarity(@RequestParam Integer reportId1,@RequestParam Integer reportId2){
        return reportService.getReportSimilarity(reportId1,reportId2);
    }

    //TODO
    @PostMapping("/subReport/{fatherId}")
    public ResultVO<ReportVO> createSubReport(@RequestBody ReportFormVO reportFormVO, @PathVariable Integer fatherId, @RequestParam Integer childid) {
        return reportService.createSubReport(reportFormVO,fatherId,childid);
    }

    //TODO
    @PostMapping("/modifyReport")
    public ResultVO<ReportVO> modifyReport(@RequestBody ReportFormVO reportFormVO, @RequestParam Integer reportid){
        return reportService.modifyReport(reportFormVO,reportid);
    }

    //TODO
    @GetMapping("/getSubReport/{reportId}")
    public ResultVO<List<SubReportInfoVO>> getSubReportList(@PathVariable Integer reportId){
        return reportService.getSubReportList(reportId);
    }

//    @GetMapping("/num")
//    public Integer getActiveness(@RequestParam Integer interval, @RequestParam Integer userId){
//        return reportService.getActiveness(interval,userId);
//    }
//
//    @GetMapping("/date")
//    public Double lastReportSubmit(@RequestParam Integer userId){
//        return reportService.getPlagiarismScore(userId);
//    }


}
